package com.his.controller;

import com.his.bean.DzmHisDoctor;
import com.his.service.DzmHisDoctorService;
import com.his.utils.ResponseResult;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/dzmhisdoctor")
public class DzmHisDoctorController {

    @Autowired
    DzmHisDoctorService dzmHisDoctorService;

    /**
     * 医生信息查询
     * @return
     */
    @GetMapping("list")
    public ResponseResult getlist(DzmHisDoctor dzmHisDoctor){
        return new ResponseResult(200,"成功",dzmHisDoctorService.getlist(dzmHisDoctor));
    }

    /**
     * 修改前查询
     */
    @GetMapping("selectDoctorId/{id}")
    public ResponseResult selectDoctorId(@PathVariable("id") String id){
        return new ResponseResult(200,"成功",dzmHisDoctorService.selectDoctorId(id));
    }

    /**
     * 修改医生信息
     */
    @PostMapping("updateDoctor")
    public ResponseResult updateDoctor(@RequestBody DzmHisDoctor dzmHisDoctor){
        System.err.println(dzmHisDoctor);
        try {
            int i = dzmHisDoctorService.updateDoctor(dzmHisDoctor);
            if(i == 1){
                return new ResponseResult(200,"修改成功",null);
            }
            return new ResponseResult(500,"修改失败",null);
        }catch (Exception e){
            return new ResponseResult(500,"修改失败",null);
        }
    }

    /**
     * 添加医生信息
     */
    @PostMapping("addDoctor")
    public ResponseResult addDoctor(@RequestBody DzmHisDoctor dzmHisDoctor){
        System.err.println(dzmHisDoctor);
        try {
            int i = dzmHisDoctorService.addDoctor(dzmHisDoctor);
            if(i == 1){
                return new ResponseResult(200,"修改成功",null);
            }
            return new ResponseResult(500,"修改失败",null);
        }catch (Exception e){
            return new ResponseResult(500,"修改失败",null);
        }
    }

    /**
     * 医生个人资料查询
     */
    @GetMapping("selectByUid/{uid}")
    public ResponseResult selectByUid(@PathVariable("uid") String uid){
        return new ResponseResult(200,"成功",dzmHisDoctorService.selectByUid(uid));
    }
}
